var json = {email:"",url:""};
	var executionNum = 0;
	var executionTime = 0;
	var exeData = {num:executionNum,current:executionTime,prev:0,times:30*1000};
	
	
	
	$(document).ready(function() {
		
		getcookie();
		
		writeEmail();
		
		//获取email的值来给定checkbox的状态
		var emailValue = $("#email").val();
		if (emailValue != "") {
			$("#autologin").attr("checked", true);
		} else {
			$("#autologin").attr("checked", false);
		}
		$('#autologin').tooltip('toggle');
		
	});
	
	$("#denglv").click(function(){
		
		remembereMail();
		
	});
	
	//记住账户
	function remembereMail(){
		if ($("#autologin").is(":checked")) {
			//选中记住账户框
			//判断是否存在COOKIE
			if($.cookie){
				$.cookie.json = true;
				//判断cookie是否存在
				var data = $.cookie('mm_user');
				if(data==null){
					//创建24小时后自动销毁的cookie.
					var email = $("#email").val();
					
					var userData = {email:email};
					$.cookie('mm_user', userData,1000 * 60 * 60 * 24);
				}else{
					var email = $("#email").val();
					var userData = {email:email};
					$.cookie('mm_user', userData);
				}
			}
		}else{
			$.cookie('mm_user',null);
		}
	}
	function  writeEmail(){
		
			$.cookie.json = true;
			var data = $.cookie('mm_user');
			if(data){
				$json = $.cookie('mm_user');
				//alert($json.email);
				$("#email").attr("value",$json.email);
			}
		
	}
	

	function getcookie(){
		
		if($.cookie){
			$.cookie.json = true;
			//判断cookie是否存在
			var data = $.cookie('mm_login');
			if(data==null){
				//创建3个小时后自动销毁的cookie.
				$.cookie('mm_login', exeData,1000 * 60 * 60 * 3);	
			}else{			
				//判断current的时间与现在的时间差是否大于times
				$json = $.cookie('mm_login');
				if($json.current-$json.prev > $json.times && $json.num!=0){
					$('#tijiaoxiugai').attr('disabled',"true");
					//$(".msg").text("点击过于频繁.请10秒后再次尝试.");
				}; 
					
				
				//alertjson($.cookie('mm_login')); 
				//启动settimeout的方法
				//判断settimeout的时间.
				var nowtime = new Date().getTime();
				if(nowtime-$json.current>$json.times){
					$('#tijiaoxiugai').removeAttr('disabled');
					
				}else{
				
				setTimeout("$('#tijiaoxiugai').removeAttr('disabled');",$json.times-(nowtime-$json.current));
				}
				
			}
		}
	}
	
	function setcookie(){//点击提交时记录次数与执行时间
		
		//记录按钮被点击次数
		executionNum = executionNum+1;
		//记录按钮执行时间
		exeData.num = executionNum;
		if(exeData.current)
			exeData.prev = exeData.current;
		exeData.current = new Date().getTime();
		
		$.cookie('mm_login', exeData);
		
		//alertjson($.cookie('mm_login')); 
	}
	
	function checkEmail(){
		
	 	var isemail = validate($("#email_psw").val(),6);
		if(!isemail){
			$(".msg").text("email格式错误!请核对后再提交");
			return;
		} 
		
		$(".msg").text("正在执行操作...");
		
		var email_psw = $("#email_psw").val();
		json.url = site.web+"forget/reset";
	 	json.email = email_psw;
		
		cb = function(data){
			
			if(data.code==1){
				
				$(".msg").text(data.message);
				setcookie();
				$('#tijiaoxiugai').attr('disabled',"true");
				$json = $.cookie('mm_login');
				setTimeout("$('#tijiaoxiugai').removeAttr('disabled');",$json.times);
				
			}else{
				$(".msg").text(data.message);
			}
		};
		G(json,cb);
	}
	go =  function(){
		
	$("#form2").submit();		
	} 
	function forgotPassword() {
		$(".msg").text("");
		$("#email_psw").val("");
		$('#myModal').modal('show');
	}